﻿using Microsoft.SharePoint;

namespace System.Modules.SharePoint.Contracts.DTO
{
    /// <summary>
    /// use AllowUnsafeUpdate in using statement
    /// </summary>
    public class AllowUnsafeUpdate : IDisposable
    {
        private readonly SPWeb _web;
        /// <summary>
        /// Constructor
        /// </summary>
        public AllowUnsafeUpdate() : this(SPContext.Current.Web) { }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="web"></param>
        public AllowUnsafeUpdate(SPWeb web)
        {
            _web = web;
            if (_web != null)
            {
                _web.AllowUnsafeUpdates = true;
            }
        }
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            if (_web != null)
            {
                _web.AllowUnsafeUpdates = false;
            }
        }
    }
}